package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.vo.RealTimeDataVO;
import com.ruoyi.system.service.AgricultureService;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 农业大屏
 */
@Slf4j
@RequestMapping("/agriculture")
@RestController
public class AgricultureController {
    @Resource
    private AgricultureService agricultureService;

    @GetMapping("/subScribe")
    public AjaxResult subScribe() throws MqttException {
        log.info("subScribe mqtt broken topic");
        agricultureService.subScribe();
        return AjaxResult.success();
    }

    @GetMapping("/data")
    public AjaxResult getAgricultureData() {
        RealTimeDataVO data = agricultureService.getRealTimeData();
        return AjaxResult.success(data);
    }

    @GetMapping("/tempHistory")
    public AjaxResult getTempHistory() {
        RealTimeDataVO data = agricultureService.getTempHistory();
        return AjaxResult.success(data);
    }
}
